<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '7.5.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="numpy的用法的总结">
<meta name="keywords" content="学习笔记,Python">
<meta property="og:type" content="article">
<meta property="og:title" content="Numpy学习笔记">
<meta property="og:url" content="https:&#x2F;&#x2F;fwj1635387072.github.io&#x2F;2021&#x2F;03&#x2F;13&#x2F;numpy&#x2F;index.html">
<meta property="og:site_name" content="付文杰的博客">
<meta property="og:description" content="numpy的用法的总结">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2021-03-21T08:40:24.778Z">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://fwj1635387072.github.io/2021/03/13/numpy/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>


  <title>Numpy学习笔记 | 付文杰的博客</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">付文杰的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">个人博客  |  日常</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>

      </div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://FWj1635387072.github.io/2021/03/13/numpy/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/headImage.jpg">
      <meta itemprop="name" content="付文杰">
      <meta itemprop="description" content="兰州交通大学 | 本科生 <br> 信息管理与信息系统">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="付文杰的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Numpy学习笔记
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-03-13 19:05:27" itemprop="dateCreated datePublished" datetime="2021-03-13T19:05:27+08:00">2021-03-13</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-03-21 16:40:24" itemprop="dateModified" datetime="2021-03-21T16:40:24+08:00">2021-03-21</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Python/" itemprop="url" rel="index">
                    <span itemprop="name">Python</span>
                  </a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.8k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>13 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <pre><code>numpy的用法的总结</code></pre><a id="more"></a>

<p><code>genfromtext()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np	</span><br><span class="line"></span><br><span class="line"><span class="comment">#从txt文件中读取数据，分割符为，</span></span><br><span class="line"></span><br><span class="line">world_alcohol = np.genfromtext(<span class="string">"world_alcohol.txt"</span>,delimiter=<span class="string">","</span>)</span><br><span class="line">print(type(world_alcohol))</span><br></pre></td></tr></table></figure>

<p><code>np.array()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">vector = np.array([<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>,<span class="number">20</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment">#传入两个list作为输入，构造numpy数组</span></span><br><span class="line"></span><br><span class="line">matrix = np.array([[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>],[<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>],[<span class="number">7</span>,<span class="number">8</span>,<span class="number">9</span>]])</span><br><span class="line">print(vector)</span><br><span class="line">print(matrix)</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出numpy数组的维数，例如（4,）(2,3)</span></span><br><span class="line">print(vector.shape)</span><br><span class="line">print(matrix.shape)</span><br></pre></td></tr></table></figure>

<p><code>dtype</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">numbers = np.array([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4.0</span>])</span><br><span class="line">print(numbers)</span><br><span class="line"></span><br><span class="line"><span class="comment">#输出numbers中元素的类型（保证元素类型一致）</span></span><br><span class="line">numbers.dtype</span><br></pre></td></tr></table></figure>

<p>切片</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">vector = np.array([<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>,<span class="number">20</span>])</span><br><span class="line">print(vector)</span><br><span class="line">print(vector[<span class="number">0</span>:<span class="number">3</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment">#切片</span></span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[ <span class="number">5</span> <span class="number">10</span> <span class="number">15</span> <span class="number">20</span>]</span><br><span class="line">[ <span class="number">5</span> <span class="number">10</span> <span class="number">15</span>]</span><br></pre></td></tr></table></figure>

<p>多维切片</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">matrix = np.array([</span><br><span class="line">            [<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>],</span><br><span class="line">            [<span class="number">20</span>,<span class="number">25</span>,<span class="number">40</span>],</span><br><span class="line">            [<span class="number">35</span>,<span class="number">40</span>,<span class="number">45</span>]</span><br><span class="line">            ])</span><br><span class="line">print(matrix[:,<span class="number">0</span>:<span class="number">2</span>])</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[[ <span class="number">5</span> <span class="number">10</span>]</span><br><span class="line"> [<span class="number">20</span> <span class="number">25</span>]</span><br><span class="line"> [<span class="number">35</span> <span class="number">40</span>]]</span><br></pre></td></tr></table></figure>

<p>查找是否存在</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">vector = np.array([<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>,<span class="number">20</span>])</span><br><span class="line">vector == <span class="number">10</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#判断数组中哪个数为所示数</span></span><br><span class="line">out:</span><br><span class="line">array([<span class="literal">False</span>,  <span class="literal">True</span>, <span class="literal">False</span>, <span class="literal">False</span>])</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">matrix = np.array([</span><br><span class="line">    [<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>],</span><br><span class="line">    [<span class="number">20</span>,<span class="number">25</span>,<span class="number">30</span>],</span><br><span class="line">    [<span class="number">35</span>,<span class="number">40</span>,<span class="number">45</span>]</span><br><span class="line">])</span><br><span class="line">matrix == <span class="number">25</span></span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">array([[<span class="literal">False</span>, <span class="literal">False</span>, <span class="literal">False</span>],</span><br><span class="line">       [<span class="literal">False</span>,  <span class="literal">True</span>, <span class="literal">False</span>],</span><br><span class="line">       [<span class="literal">False</span>, <span class="literal">False</span>, <span class="literal">False</span>]])</span><br></pre></td></tr></table></figure>

<p>通过是否存在输出指定值</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">equal_to_ten = (vector == <span class="number">10</span>)</span><br><span class="line">print(equal_to_ten)</span><br><span class="line">print(vector[equal_to_ten])</span><br><span class="line"></span><br><span class="line"><span class="comment">#如何找到指定值</span></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[<span class="literal">False</span>  <span class="literal">True</span> <span class="literal">False</span> <span class="literal">False</span>]</span><br><span class="line">[<span class="number">10</span>]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">equal_to_ten = (matrix == <span class="number">10</span>)</span><br><span class="line">print(equal_to_ten)</span><br><span class="line">print(matrix[equal_to_ten])</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">equal_to_ten = (matrix == <span class="number">10</span>)</span><br><span class="line">print(equal_to_ten)</span><br><span class="line">print(matrix[equal_to_ten])</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[[<span class="literal">False</span>  <span class="literal">True</span> <span class="literal">False</span>]</span><br><span class="line"> [<span class="literal">False</span> <span class="literal">False</span> <span class="literal">False</span>]</span><br><span class="line"> [<span class="literal">False</span> <span class="literal">False</span> <span class="literal">False</span>]]</span><br><span class="line">[<span class="number">10</span>]</span><br></pre></td></tr></table></figure>

<p>输出指定条件下的指定元素</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">matrix = np.array([</span><br><span class="line">    [<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>],</span><br><span class="line">    [<span class="number">20</span>,<span class="number">25</span>,<span class="number">30</span>],</span><br><span class="line">    [<span class="number">35</span>,<span class="number">40</span>,<span class="number">45</span>]</span><br><span class="line">])</span><br><span class="line">second_column_25 = (matrix[:,<span class="number">1</span>]==<span class="number">25</span>)</span><br><span class="line">print(second_column_25)</span><br><span class="line">print(matrix[second_column_25,:])</span><br><span class="line"></span><br><span class="line"><span class="comment">#找到第二列中25所在行，输出该行所有元素</span></span><br><span class="line">out：</span><br><span class="line">[<span class="literal">False</span>  <span class="literal">True</span> <span class="literal">False</span>]</span><br><span class="line">[[<span class="number">20</span> <span class="number">25</span> <span class="number">30</span>]]</span><br></pre></td></tr></table></figure>

<p>查找指定元素时，可以使用逻辑运算</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">vector = np.array([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>,<span class="number">7</span>])</span><br><span class="line">be_divided_by_2_and_3 = (vector % <span class="number">2</span> == <span class="number">0</span>) &amp; (vector % <span class="number">3</span> == <span class="number">0</span>)</span><br><span class="line">print(be_divided_by_2_and_3)</span><br><span class="line">print(vector[be_divided_by_2_and_3])</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[<span class="literal">False</span> <span class="literal">False</span> <span class="literal">False</span> <span class="literal">False</span> <span class="literal">False</span>  <span class="literal">True</span> <span class="literal">False</span>]</span><br><span class="line">[<span class="number">6</span>]</span><br></pre></td></tr></table></figure>

<p>将第二列中，值为25的元素改为10</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">matrix = np.array([</span><br><span class="line">    [<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>],</span><br><span class="line">    [<span class="number">20</span>,<span class="number">25</span>,<span class="number">30</span>],</span><br><span class="line">    [<span class="number">35</span>,<span class="number">40</span>,<span class="number">45</span>]</span><br><span class="line">])</span><br><span class="line">second_column_equal_25 = (matrix[:,<span class="number">1</span>] == <span class="number">25</span>)</span><br><span class="line">print(second_column_equal_25)</span><br><span class="line">matrix[second_column_equal_25,<span class="number">1</span>]=<span class="number">10</span></span><br><span class="line">print(matrix)</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[<span class="literal">False</span>  <span class="literal">True</span> <span class="literal">False</span>]</span><br><span class="line">[[ <span class="number">5</span> <span class="number">10</span> <span class="number">15</span>]</span><br><span class="line"> [<span class="number">20</span> <span class="number">10</span> <span class="number">30</span>]</span><br><span class="line"> [<span class="number">35</span> <span class="number">40</span> <span class="number">45</span>]]</span><br></pre></td></tr></table></figure>

<p>numpy元素转换<code>astype()</code>        </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">vector = np.array([<span class="string">"1"</span>,<span class="string">"2"</span>,<span class="string">"3"</span>])</span><br><span class="line">print(vector.dtype)</span><br><span class="line">print(vector)</span><br><span class="line">vector = vector.astype(float)</span><br><span class="line">print(vector)</span><br><span class="line">print(vector.dtype)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">&lt;U1</span><br><span class="line">[<span class="string">'1'</span> <span class="string">'2'</span> <span class="string">'3'</span>]</span><br><span class="line">[<span class="number">1.</span> <span class="number">2.</span> <span class="number">3.</span>]</span><br><span class="line">float64</span><br></pre></td></tr></table></figure>

<p><code>sum()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">vector =  np.array([<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>,<span class="number">20</span>])</span><br><span class="line">print(vector.sum())</span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">    <span class="number">50</span></span><br></pre></td></tr></table></figure>

<p>多维向量分别对行和列进行求和</p>
<p><code>axis=1</code>表示列</p>
<p><code>axis=0</code>表示行</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">matrix = np.array([</span><br><span class="line">    [<span class="number">5</span>,<span class="number">10</span>,<span class="number">15</span>],</span><br><span class="line">    [<span class="number">20</span>,<span class="number">25</span>,<span class="number">30</span>],</span><br><span class="line">    [<span class="number">35</span>,<span class="number">40</span>,<span class="number">45</span>]</span><br><span class="line">])</span><br><span class="line">print(matrix.sum(axis=<span class="number">0</span>))</span><br><span class="line">print(matrix.sum(axis=<span class="number">1</span>))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[<span class="number">60</span> <span class="number">75</span> <span class="number">90</span>]</span><br><span class="line">[ <span class="number">30</span>  <span class="number">75</span> <span class="number">120</span>]</span><br></pre></td></tr></table></figure>

<p><code>isnan</code></p>
<p>将得到数据，第四行为空值的设置为均值</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">world_alcohol = np.genfromtxt(<span class="string">"world_alcohol.txt"</span>,delimiter=<span class="string">','</span>)</span><br><span class="line"><span class="comment">#print(world_alcohol)</span></span><br><span class="line">is_value_null = np.isnan(world_alcohol[:,<span class="number">4</span>])</span><br><span class="line"><span class="comment">#print(is_value_null)</span></span><br><span class="line">world_alcohol[is_value_null,<span class="number">4</span>] = <span class="string">'0'</span></span><br><span class="line">alcohol_comsumption = world_alcohol[:,<span class="number">4</span>]</span><br><span class="line">alcohol_comsumption = alcohol_comsumption.astype(float)</span><br><span class="line">alcohol_total = alcohol_comsumption.sum();</span><br><span class="line">alcohol_mean = alcohol_comsumption.mean();</span><br><span class="line">print(alcohol_total)</span><br><span class="line">print(alcohol_mean)</span><br><span class="line">world_alcohol[is_value_null,<span class="number">4</span>] = alcohol_mean</span><br><span class="line">print(world_alcohol)</span><br></pre></td></tr></table></figure>

<p><code>arrange(begin,end,internal)</code>,默认begin从0开始，左闭右开。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">print(np.arange(<span class="number">10</span>,<span class="number">20</span>))</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[<span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span> <span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span>]</span><br></pre></td></tr></table></figure>

<p><code>reshape(row,col)</code>：将numpy数组改变为指定的形状，-1表示自动改变</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">a = np.arange(<span class="number">10</span>).reshape(<span class="number">2</span>,<span class="number">-1</span>)</span><br><span class="line">print(a)</span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[[<span class="number">0</span> <span class="number">1</span> <span class="number">2</span> <span class="number">3</span> <span class="number">4</span>]</span><br><span class="line"> [<span class="number">5</span> <span class="number">6</span> <span class="number">7</span> <span class="number">8</span> <span class="number">9</span>]]</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">a = np.arange(<span class="number">0</span>,<span class="number">10</span>,<span class="number">1</span>).reshape(<span class="number">2</span>,<span class="number">5</span>)</span><br><span class="line">print(a)</span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[[<span class="number">0</span> <span class="number">1</span> <span class="number">2</span> <span class="number">3</span> <span class="number">4</span>]</span><br><span class="line"> [<span class="number">5</span> <span class="number">6</span> <span class="number">7</span> <span class="number">8</span> <span class="number">9</span>]]</span><br></pre></td></tr></table></figure>

<p><code>ones((row,col),dtype= )    zeros(...)</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">a = np.ones((<span class="number">2</span>,<span class="number">3</span>))</span><br><span class="line">print(a)</span><br><span class="line">print(a.dtype)</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[[<span class="number">1.</span> <span class="number">1.</span> <span class="number">1.</span>]</span><br><span class="line"> [<span class="number">1.</span> <span class="number">1.</span> <span class="number">1.</span>]]</span><br><span class="line">float64</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">b = np.zeros((<span class="number">2</span>,<span class="number">3</span>),dtype=np.int32)</span><br><span class="line">print(b)</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[[<span class="number">0</span> <span class="number">0</span> <span class="number">0</span>]</span><br><span class="line"> [<span class="number">0</span> <span class="number">0</span> <span class="number">0</span>]]</span><br></pre></td></tr></table></figure>

<p>​    <code>random</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">a = np.random.random((<span class="number">2</span>,<span class="number">3</span>))</span><br><span class="line">print(a)</span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[[<span class="number">0.25455831</span> <span class="number">0.21875025</span> <span class="number">0.9586944</span> ]</span><br><span class="line"> [<span class="number">0.03249533</span> <span class="number">0.525685</span>   <span class="number">0.64446951</span>]]</span><br></pre></td></tr></table></figure>

<p>numpy数组运算</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">a = np.array([<span class="number">10</span>,<span class="number">20</span>,<span class="number">30</span>,<span class="number">40</span>])</span><br><span class="line">b = np.arange(<span class="number">4</span>)</span><br><span class="line">print(a + b)</span><br><span class="line">print(a - b)</span><br><span class="line">print(a * b)</span><br><span class="line">print(a**<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[<span class="number">10</span> <span class="number">21</span> <span class="number">32</span> <span class="number">43</span>]</span><br><span class="line">[<span class="number">10</span> <span class="number">19</span> <span class="number">28</span> <span class="number">37</span>]</span><br><span class="line">[  <span class="number">0</span>  <span class="number">20</span>  <span class="number">60</span> <span class="number">120</span>]</span><br><span class="line">[ <span class="number">100</span>  <span class="number">400</span>  <span class="number">900</span> <span class="number">1600</span>]</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">A = np.array([</span><br><span class="line">    [<span class="number">1</span>,<span class="number">1</span>],</span><br><span class="line">    [<span class="number">0</span>,<span class="number">1</span>]</span><br><span class="line">])</span><br><span class="line">B = np.array([</span><br><span class="line">    [<span class="number">2</span>,<span class="number">0</span>],</span><br><span class="line">    [<span class="number">3</span>,<span class="number">4</span>]</span><br><span class="line">])</span><br><span class="line">print(A)</span><br><span class="line">print(B)</span><br><span class="line">print(<span class="string">"*"</span> * <span class="number">6</span>)</span><br><span class="line">print(A*B)</span><br><span class="line">print(<span class="string">"*"</span> * <span class="number">6</span>)</span><br><span class="line">print(A.dot(B))</span><br><span class="line">print(<span class="string">"*"</span> * <span class="number">6</span>)</span><br><span class="line">print(np.dot(A,B))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[[<span class="number">1</span> <span class="number">1</span>]</span><br><span class="line"> [<span class="number">0</span> <span class="number">1</span>]]</span><br><span class="line">[[<span class="number">2</span> <span class="number">0</span>]</span><br><span class="line"> [<span class="number">3</span> <span class="number">4</span>]]</span><br><span class="line">******</span><br><span class="line">[[<span class="number">2</span> <span class="number">0</span>]</span><br><span class="line"> [<span class="number">0</span> <span class="number">4</span>]]</span><br><span class="line">******</span><br><span class="line">[[<span class="number">5</span> <span class="number">4</span>]</span><br><span class="line"> [<span class="number">3</span> <span class="number">4</span>]]</span><br><span class="line">******</span><br><span class="line">[[<span class="number">5</span> <span class="number">4</span>]</span><br><span class="line"> [<span class="number">3</span> <span class="number">4</span>]]</span><br></pre></td></tr></table></figure>

<p>数组合并和拆分</p>
<p><code>hstack()</code>：横向合并</p>
<p><code>vstack()</code>：纵向合并</p>
<p><code>hsplit()</code>：横向拆分</p>
<p><code>vsplit()</code>：纵向拆分</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">a = np.floor(<span class="number">10</span>*np.random.random((<span class="number">2</span>,<span class="number">2</span>)))</span><br><span class="line">b = np.floor(<span class="number">10</span>*np.random.random((<span class="number">2</span>,<span class="number">2</span>)))</span><br><span class="line">print(a)</span><br><span class="line">print(<span class="string">"*"</span> * <span class="number">10</span>)</span><br><span class="line">print(b)</span><br><span class="line">print(<span class="string">"*"</span> * <span class="number">10</span>)</span><br><span class="line">print(np.vstack((a,b)))</span><br><span class="line">print(<span class="string">"*"</span> * <span class="number">10</span>)</span><br><span class="line">print(np.hstack((a,b)))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">    [[<span class="number">1.</span> <span class="number">0.</span>]</span><br><span class="line"> [<span class="number">6.</span> <span class="number">6.</span>]]</span><br><span class="line">**********</span><br><span class="line">[[<span class="number">6.</span> <span class="number">6.</span>]</span><br><span class="line"> [<span class="number">3.</span> <span class="number">9.</span>]]</span><br><span class="line">**********</span><br><span class="line">[[<span class="number">1.</span> <span class="number">0.</span>]</span><br><span class="line"> [<span class="number">6.</span> <span class="number">6.</span>]</span><br><span class="line"> [<span class="number">6.</span> <span class="number">6.</span>]</span><br><span class="line"> [<span class="number">3.</span> <span class="number">9.</span>]]</span><br><span class="line">**********</span><br><span class="line">[[<span class="number">1.</span> <span class="number">0.</span> <span class="number">6.</span> <span class="number">6.</span>]</span><br><span class="line"> [<span class="number">6.</span> <span class="number">6.</span> <span class="number">3.</span> <span class="number">9.</span>]]</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">a = np.floor(<span class="number">10</span>*np.random.random((<span class="number">2</span>,<span class="number">6</span>)))</span><br><span class="line">print(a)</span><br><span class="line">print(np.hsplit(a,<span class="number">3</span>))</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[[<span class="number">8.</span> <span class="number">0.</span> <span class="number">0.</span> <span class="number">8.</span> <span class="number">6.</span> <span class="number">1.</span>]</span><br><span class="line"> [<span class="number">1.</span> <span class="number">8.</span> <span class="number">1.</span> <span class="number">3.</span> <span class="number">6.</span> <span class="number">1.</span>]]</span><br><span class="line">[array([[<span class="number">8.</span>, <span class="number">0.</span>],</span><br><span class="line">       [<span class="number">1.</span>, <span class="number">8.</span>]]), array([[<span class="number">0.</span>, <span class="number">8.</span>],</span><br><span class="line">       [<span class="number">1.</span>, <span class="number">3.</span>]]), array([[<span class="number">6.</span>, <span class="number">1.</span>],</span><br><span class="line">       [<span class="number">6.</span>, <span class="number">1.</span>]])]</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">a = np.floor(<span class="number">10</span>*np.random.random((<span class="number">2</span>,<span class="number">6</span>)))</span><br><span class="line">print(a)</span><br><span class="line">print(np.hsplit(a,(<span class="number">3</span>,<span class="number">5</span>)))</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[[<span class="number">8.</span> <span class="number">4.</span> <span class="number">1.</span> <span class="number">8.</span> <span class="number">5.</span> <span class="number">2.</span>]</span><br><span class="line"> [<span class="number">6.</span> <span class="number">4.</span> <span class="number">2.</span> <span class="number">0.</span> <span class="number">7.</span> <span class="number">9.</span>]]</span><br><span class="line">[array([[<span class="number">8.</span>, <span class="number">4.</span>, <span class="number">1.</span>],</span><br><span class="line">       [<span class="number">6.</span>, <span class="number">4.</span>, <span class="number">2.</span>]]), array([[<span class="number">8.</span>, <span class="number">5.</span>],</span><br><span class="line">       [<span class="number">0.</span>, <span class="number">7.</span>]]), array([[<span class="number">2.</span>],</span><br><span class="line">       [<span class="number">9.</span>]])]</span><br></pre></td></tr></table></figure>

<p><code>r_</code>：上下合并</p>
<p><code>c_</code>：左右合并</p>
<p>引用地址:</p>
<p>​    使用copy（）,开辟新的内存空间。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">a = np.array([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])</span><br><span class="line">b = a.view();</span><br><span class="line">print(str(a) + <span class="string">"\n"</span> +str(b))</span><br><span class="line">a[<span class="number">2</span>] = <span class="number">111</span></span><br><span class="line">print(str(a) + <span class="string">"\n"</span> +str(b))</span><br><span class="line">b[<span class="number">2</span>] = <span class="number">3</span></span><br><span class="line">print(str(a) + <span class="string">"\n"</span> +str(b))</span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br><span class="line">[  <span class="number">1</span>   <span class="number">2</span> <span class="number">111</span>]</span><br><span class="line">[  <span class="number">1</span>   <span class="number">2</span> <span class="number">111</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">a = np.array([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>])</span><br><span class="line">b = a.copy();</span><br><span class="line">print(str(a) + <span class="string">"\n"</span> +str(b))</span><br><span class="line">a[<span class="number">2</span>] = <span class="number">111</span></span><br><span class="line">print(str(a) + <span class="string">"\n"</span> +str(b))</span><br><span class="line">b[<span class="number">2</span>] = <span class="number">3</span></span><br><span class="line">print(str(a) + <span class="string">"\n"</span> +str(b))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br><span class="line">[  <span class="number">1</span>   <span class="number">2</span> <span class="number">111</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br><span class="line">[  <span class="number">1</span>   <span class="number">2</span> <span class="number">111</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span>]</span><br></pre></td></tr></table></figure>

<p><code>tile()平铺</code>：将传入的矩阵看作元素，复制为指定的矩阵。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">a = np.arange(<span class="number">0</span>,<span class="number">40</span>,<span class="number">10</span>)</span><br><span class="line">b= np.tile(a,(<span class="number">3</span>,<span class="number">5</span>))</span><br><span class="line">print(a)</span><br><span class="line">print(b)</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[ <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>]</span><br><span class="line">[[ <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>]</span><br><span class="line"> [ <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>]</span><br><span class="line"> [ <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>  <span class="number">0</span> <span class="number">10</span> <span class="number">20</span> <span class="number">30</span>]]</span><br></pre></td></tr></table></figure>

<p><code>argsort()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">a = np.array([<span class="number">4</span>,<span class="number">3</span>,<span class="number">1</span>,<span class="number">2</span>])</span><br><span class="line">j = np.argsort(a)</span><br><span class="line">print(j)</span><br><span class="line">print(a[j])</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[<span class="number">2</span> <span class="number">3</span> <span class="number">1</span> <span class="number">0</span>]</span><br><span class="line">[<span class="number">1</span> <span class="number">2</span> <span class="number">3</span> <span class="number">4</span>]</span><br></pre></td></tr></table></figure>

<p>交换矩阵的其中两行/列</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">a = np.arange(<span class="number">25</span>).reshape(<span class="number">5</span>,<span class="number">-1</span>)</span><br><span class="line">print(a)</span><br><span class="line">a[[<span class="number">2</span>,<span class="number">1</span>],:] = a[[<span class="number">1</span>,<span class="number">2</span>],:]</span><br><span class="line"></span><br><span class="line"><span class="comment">#a[:,[1,2]] = a[:,[2,1]]</span></span><br><span class="line">print(a)</span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[[ <span class="number">0</span>  <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>]</span><br><span class="line"> [ <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span>]</span><br><span class="line"> [<span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span>]</span><br><span class="line"> [<span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span>]</span><br><span class="line"> [<span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span>]]</span><br><span class="line">[[ <span class="number">0</span>  <span class="number">1</span>  <span class="number">2</span>  <span class="number">3</span>  <span class="number">4</span>]</span><br><span class="line"> [<span class="number">10</span> <span class="number">11</span> <span class="number">12</span> <span class="number">13</span> <span class="number">14</span>]</span><br><span class="line"> [ <span class="number">5</span>  <span class="number">6</span>  <span class="number">7</span>  <span class="number">8</span>  <span class="number">9</span>]</span><br><span class="line"> [<span class="number">15</span> <span class="number">16</span> <span class="number">17</span> <span class="number">18</span> <span class="number">19</span>]</span><br><span class="line"> [<span class="number">20</span> <span class="number">21</span> <span class="number">22</span> <span class="number">23</span> <span class="number">24</span>]]</span><br></pre></td></tr></table></figure>

<p>找出数组中与给定值最接近的数的下标</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">z = np.array([[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">55</span>],[<span class="number">4</span>,<span class="number">1</span>,<span class="number">5</span>,<span class="number">1</span>,<span class="number">1</span>]])</span><br><span class="line">a = <span class="number">5.1</span></span><br><span class="line">print(np.abs(z-a).argmin())</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line"><span class="number">7</span></span><br></pre></td></tr></table></figure>

<p>Numpy中更好的遍历方式<code>apply_along_axis</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">x = np.arange(<span class="number">11</span>,<span class="number">36</span>).reshape(<span class="number">5</span>,<span class="number">5</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">y = np.apply_along_axis(np.sum, <span class="number">0</span>, x)</span><br><span class="line">print(y)</span><br><span class="line"></span><br><span class="line">y = np.apply_along_axis(np.sum,<span class="number">1</span>,x)</span><br><span class="line">print(y)</span><br></pre></td></tr></table></figure>

<p>矩阵转置<code>transpose()</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">a = np.arange(<span class="number">10</span>).reshape(<span class="number">2</span>,<span class="number">5</span>).transpose()</span><br><span class="line">print(a)</span><br></pre></td></tr></table></figure>

<p>使用numpy计算移动平均数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">np.random.seed(<span class="number">100</span>)</span><br><span class="line">z = np.random.randint(<span class="number">10</span>,size = <span class="number">10</span>)</span><br><span class="line">print(z)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">MovingAverage</span><span class="params">(arr, n = <span class="number">3</span>)</span>:</span></span><br><span class="line">    a = np.cumsum(arr)</span><br><span class="line">    a[n:] = a[n:] - a[:-n]</span><br><span class="line">    <span class="keyword">return</span> a[n - <span class="number">1</span>:] / n     </span><br><span class="line">    </span><br><span class="line">r = MovingAverage(z,<span class="number">3</span>)</span><br><span class="line">print(np.around(r,<span class="number">2</span>))</span><br></pre></td></tr></table></figure>

<p>对5*5的矩阵进行归一化</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Z = np.random.random((<span class="number">5</span>,<span class="number">5</span>))</span><br><span class="line">Zmax,Zmin = Z.max(),Z.min()</span><br><span class="line">Z = (Z - Zmin) / (Zmax - Zmin)</span><br><span class="line">print(Z)</span><br></pre></td></tr></table></figure>

<p>排序</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#获得排序后的下标  argsort()</span></span><br><span class="line">np.random.seed(<span class="number">20200612</span>)</span><br><span class="line">x = np.random.randint(<span class="number">0</span>,<span class="number">10</span>,<span class="number">10</span>)</span><br><span class="line">print(x)</span><br><span class="line"></span><br><span class="line">y = np.argsort(x)</span><br><span class="line">print(y)</span><br><span class="line"></span><br><span class="line">print(x[y])</span><br><span class="line"></span><br><span class="line">y = np.argsort(-x)</span><br><span class="line">print(y)</span><br><span class="line">print(x[y])</span><br><span class="line"></span><br><span class="line"><span class="comment">#按照某列或行对整体进行排序  lexsort()</span></span><br><span class="line">x = np.random.rand(<span class="number">5</span>,<span class="number">5</span>) * <span class="number">10</span></span><br><span class="line">x = np.around(x,<span class="number">2</span>)</span><br><span class="line">print(x)</span><br><span class="line"></span><br><span class="line">index = np.lexsort([x[:,<span class="number">0</span>]])</span><br><span class="line">print(index)</span><br><span class="line">y = x[index]</span><br><span class="line">print(y)</span><br><span class="line"></span><br><span class="line"><span class="comment">#partition()，以下标为kth的元素为基准</span></span><br><span class="line"><span class="comment">#将元素分为两部分，小于某元素放前面，大于放后面。</span></span><br><span class="line">x = np.random.randint(<span class="number">1</span>,<span class="number">20</span>,[<span class="number">1</span>,<span class="number">15</span>])</span><br><span class="line">print(x)</span><br><span class="line">y = np.partition(x,kth=<span class="number">3</span>)</span><br><span class="line">print(y)</span><br><span class="line"><span class="comment">#取出每一列第三小的元素</span></span><br><span class="line">x = np.random.randint(<span class="number">1</span>,<span class="number">20</span>,[<span class="number">5</span>,<span class="number">3</span>])</span><br><span class="line">y = np.partition(x,kth=<span class="number">3</span>,axis=<span class="number">0</span>)</span><br><span class="line">print(y)</span><br><span class="line">print(y[<span class="number">2</span>,:])</span><br><span class="line"></span><br><span class="line"><span class="comment">#count_nonzero()记录非零元素个数</span></span><br></pre></td></tr></table></figure>



<p>numpy中和线性代数相关的函数</p>
<table>
<thead>
<tr>
<th align="center">函数</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">diag</td>
<td align="center">将一个方阵的对角元素作为一位数组返回，或将一个一位数组转换为方阵，并在非对角线上有零点。</td>
</tr>
<tr>
<td align="center">dot</td>
<td align="center">矩阵点乘</td>
</tr>
<tr>
<td align="center">trace</td>
<td align="center">计算对角元素和</td>
</tr>
<tr>
<td align="center">det</td>
<td align="center">计算行列式</td>
</tr>
<tr>
<td align="center">eig</td>
<td align="center">计算方阵的特征值和特征向量</td>
</tr>
<tr>
<td align="center">inv</td>
<td align="center">计算方针的逆矩阵</td>
</tr>
<tr>
<td align="center">pinv</td>
<td align="center">计算方阵的Moore-Penrose伪逆</td>
</tr>
<tr>
<td align="center">qr</td>
<td align="center">计算QR分解</td>
</tr>
<tr>
<td align="center">svd</td>
<td align="center">计算奇异值分解</td>
</tr>
<tr>
<td align="center">solve</td>
<td align="center">求解x的线性系统Ax=b，其中A为方阵</td>
</tr>
<tr>
<td align="center">lstsq</td>
<td align="center">计算Ax=B的最小二乘解</td>
</tr>
</tbody></table>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"></span><br><span class="line">a = np.array([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>])</span><br><span class="line">b = np.diag(a)</span><br><span class="line">print(b)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">out:</span><br><span class="line">[[<span class="number">1</span> <span class="number">0</span> <span class="number">0</span> <span class="number">0</span>]</span><br><span class="line"> [<span class="number">0</span> <span class="number">2</span> <span class="number">0</span> <span class="number">0</span>]</span><br><span class="line"> [<span class="number">0</span> <span class="number">0</span> <span class="number">3</span> <span class="number">0</span>]</span><br><span class="line"> [<span class="number">0</span> <span class="number">0</span> <span class="number">0</span> <span class="number">4</span>]]</span><br><span class="line"></span><br><span class="line"><span class="comment">#计算对角元素和</span></span><br><span class="line">print(np.trace(b))</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line"><span class="number">10</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#计算行列式</span></span><br><span class="line">print(np.linalg.det(b))</span><br><span class="line">out：</span><br><span class="line"><span class="number">23.999999999999993</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#计算方阵的特征向量</span></span><br><span class="line">c = np.linalg.eig(b)</span><br><span class="line">print(c[<span class="number">1</span>])</span><br><span class="line"></span><br><span class="line">out</span><br><span class="line">[[<span class="number">1.</span> <span class="number">0.</span> <span class="number">0.</span> <span class="number">0.</span>]</span><br><span class="line"> [<span class="number">0.</span> <span class="number">1.</span> <span class="number">0.</span> <span class="number">0.</span>]</span><br><span class="line"> [<span class="number">0.</span> <span class="number">0.</span> <span class="number">1.</span> <span class="number">0.</span>]</span><br><span class="line"> [<span class="number">0.</span> <span class="number">0.</span> <span class="number">0.</span> <span class="number">1.</span>]]</span><br><span class="line"></span><br><span class="line"><span class="comment">#计算方针的逆矩阵</span></span><br><span class="line">print(np.linalg.inv(b))</span><br><span class="line"></span><br><span class="line">out：</span><br><span class="line">[[<span class="number">1.</span>         <span class="number">0.</span>         <span class="number">0.</span>         <span class="number">0.</span>        ]</span><br><span class="line"> [<span class="number">0.</span>         <span class="number">0.5</span>        <span class="number">0.</span>         <span class="number">0.</span>        ]</span><br><span class="line"> [<span class="number">0.</span>         <span class="number">0.</span>         <span class="number">0.33333333</span> <span class="number">0.</span>        ]</span><br><span class="line"> [<span class="number">0.</span>         <span class="number">0.</span>         <span class="number">0.</span>         <span class="number">0.25</span>      ]]</span><br><span class="line"></span><br><span class="line"><span class="comment">#求解x的线性系统</span></span><br><span class="line">print(np.linalg.solve(b,a.T))</span><br><span class="line">out：</span><br><span class="line">[<span class="number">1.</span> <span class="number">1.</span> <span class="number">1.</span> <span class="number">1.</span>]</span><br></pre></td></tr></table></figure>

<p>伪随机数生成</p>
<table>
<thead>
<tr>
<th align="center">函数</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">seed</td>
<td align="center">随机数种子</td>
</tr>
<tr>
<td align="center">permutation</td>
<td align="center">返回一个序列的随机排列，或者返回一个乱序的整数范围序列</td>
</tr>
<tr>
<td align="center">shuffle</td>
<td align="center">随机排列一个序列</td>
</tr>
<tr>
<td align="center">rand</td>
<td align="center">从均匀分布中抽取样本</td>
</tr>
<tr>
<td align="center">randint</td>
<td align="center">根据给定的由低到高的范围抽取整数</td>
</tr>
<tr>
<td align="center">randn</td>
<td align="center">从均值0，方差1的正太分布中抽取样本</td>
</tr>
<tr>
<td align="center">binomial</td>
<td align="center">从二项分布中抽取样本</td>
</tr>
<tr>
<td align="center">normal</td>
<td align="center">从正态（高斯）分布中抽取样本</td>
</tr>
<tr>
<td align="center">beta</td>
<td align="center">从beta分布中抽取样本</td>
</tr>
<tr>
<td align="center">chisquare</td>
<td align="center">从卡方分布中抽取样本</td>
</tr>
<tr>
<td align="center">gamma</td>
<td align="center">从伽马分布中抽取样本</td>
</tr>
<tr>
<td align="center">uniform</td>
<td align="center">从均匀[0，1）分布中抽取样本</td>
</tr>
</tbody></table>
<p>常用函数：</p>
<p><code>where</code>、<code>nonzero</code>、<code>argmax</code>、<code>argmin</code>、<code>any</code>、<code>all</code>、<code>cumprod  cumsum diff</code></p>
<p>常用统计函数：</p>
<p><code>max min  mean  median  std  var  sum  quantile</code>，略过缺失值对应有<code>nan*</code>函数</p>
<p>协方差和相关系数</p>
<p><code>cov</code> 、<code>corrcoef</code></p>

    </div>

    
    
    

      
      <div>
        
          <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
        
      </div>

      <footer class="post-footer">



        
<div>    
 
 
<ul class="post-copyright">
  <li class="post-copyright-author">
      <strong>本文作者：</strong>付文杰
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="/2021/03/13/numpy/" title="Numpy学习笔记">2021/03/13/numpy/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权： </strong>
    本站文章均采用 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0 CN</a> 许可协议，请勿用于商业，转载注明出处！
  </li>
</ul>

</div>
          <div class="post-tags">
              <a href="/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" rel="tag"><i class="fa fa-tag"></i> 学习笔记</a>
              <a href="/tags/Python/" rel="tag"><i class="fa fa-tag"></i> Python</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
                <a href="/2021/03/13/Shell/" rel="next" title="Shell学习">
                  <i class="fa fa-chevron-left"></i> Shell学习
                </a>
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
                <a href="/2021/03/14/pandas/" rel="prev" title="Pandas学习笔记01">
                  Pandas学习笔记01 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=27588222&auto=1&height=66"></iframe>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <img class="site-author-image" itemprop="image" alt="付文杰"
    src="/images/headImage.jpg">
  <p class="site-author-name" itemprop="name">付文杰</p>
  <div class="site-description" itemprop="description">兰州交通大学 | 本科生 <br> 信息管理与信息系统</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">63</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/FWj1635387072" title="GitHub &amp;rarr; https:&#x2F;&#x2F;github.com&#x2F;FWj1635387072" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/mailto:1635387072@qq.com" title="E-Mail &amp;rarr; mailto:1635387072@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/null" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>





      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        


<div class="copyright">
  
  &copy; 2019 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">付文杰</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">210k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">5:50</span>

  <br>
  <span id="sitetime"></span>

</div>
<script language=javascript>
    function siteTime() {
        window.setTimeout("siteTime()", 1000);
        var seconds = 1000;
        var minutes = seconds * 60;
        var hours = minutes * 60;
        var days = hours * 24;
        var years = days * 365;
        var today = new Date();
        var todayYear = today.getFullYear();
        var todayMonth = today.getMonth() + 1;
        var todayDate = today.getDate();
        var todayHour = today.getHours();
        var todayMinute = today.getMinutes();
        var todaySecond = today.getSeconds();
        /* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
        year - 作为date对象的年份，为4位年份值
        month - 0-11之间的整数，做为date对象的月份
        day - 1-31之间的整数，做为date对象的天数
        hours - 0(午夜24点)-23之间的整数，做为date对象的小时数
        minutes - 0-59之间的整数，做为date对象的分钟数
        seconds - 0-59之间的整数，做为date对象的秒数
        microseconds - 0-999之间的整数，做为date对象的毫秒数 */
        var t1 = Date.UTC(2019, 11, 7, 17, 50, 00); //北京时间2018-2-13 00:00:00
        var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
        var diff = t2 - t1;
        var diffYears = Math.floor(diff / years);
        var diffDays = Math.floor((diff / days) - diffYears * 365);
        var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
        var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) / minutes);
        var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours - diffMinutes * minutes) / seconds);
        document.getElementById("sitetime").innerHTML = "本站已运行 " +diffYears+" 年 "+diffDays + " 天 " + diffHours + " 小时 " + diffMinutes + " 分钟 " + diffSeconds + " 秒";
    }/*因为建站时间还没有一年，就将之注释掉了。需要的可以取消*/
    siteTime();
</script>


        












        
      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>



  
















  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":false},"symbols_count_time":null,"symbols":true,"time":true,"total_symbols":true,"total_time":true,"log":false});</script></body>
</html>
<script type="text/javascript" src="/js/src/clicklove.js"></script>